
var edr = "", req = "";
var debug = false;
/**
 * Generates the HTTP request
 * @param {type} elementToUpdate the id of the element where you wish the response to display in
 * @returns {ActiveXObject}
 */
function getXmlHttpRequest(elementToUpdate) {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        localParamRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        localParamRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    localParamRequest.onreadystatechange = function()
    {
        if (localParamRequest.readyState === 4 && localParamRequest.status === 200)
        {
            var text = localParamRequest.responseText;
            console.log("return (" + elementToUpdate + "): " + text);
            document.getElementById(elementToUpdate).innerHTML = text;
        }
    }
    return localParamRequest;
}

function getXmlHttpRequest2(elementToUpdate) {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        localParamRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        localParamRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    localParamRequest.onreadystatechange = function()
    {
        if (localParamRequest.readyState === 4 && localParamRequest.status === 200)
        {
            var text = localParamRequest.responseText;
            console.log("return (" + elementToUpdate + "): " + text);
            document.getElementById(elementToUpdate).value = text;
        }
    }
    return localParamRequest;
}

function checkFilename(button) {
    console.log("ID: " + button.id);
    var filename = button.id;
    request = getXmlHttpRequest(null);
    request.open("GET", "populateDropdown.php?type=doesFileExist&filename=" + filename, true);
    request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    request.send();
    
    console.log(localParamRequest.responseText);
}
function updateTaskFinancial(btnObj) {
    // console.log("id:" + btnObj.id);
    console.log("name:" + btnObj.name);
    // console.log("value:" + btnObj.value);
    var person = prompt("Enter new Value", btnObj.value);
    if (person !== null && person !== '') {
        if (!isNaN(person)) {
            var oldValue = document.getElementById(btnObj.id).value;
            //console.log("Old: "+oldValue);
            var newValue = person;
            //console.log("New: "+person);            
            request = getXmlHttpRequest2(btnObj.id);
            request.open("GET", "populateDropdown.php?type=updateFinancials&value=" + person + "&string=" + btnObj.name, true);
            request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            request.send();

            var buttonIndex = btnObj.name.substr(btnObj.name.length - 1);
            var totalId = "";
            if (btnObj.name.indexOf("hours") > -1) {
                totalId = "totalHour" + buttonIndex;
            }
            else {
                totalId = "totalCost" + buttonIndex;
            }
            //console.log("Tot ("+totalId+"): "+document.getElementById(totalId).innerHTML);
            document.getElementById(totalId).innerHTML = parseInt(document.getElementById(totalId).innerHTML) + parseInt(newValue - oldValue);
        }
        else {
            //console.log("NaN");
            alert("Must be a number");
            //return null;
        }
    }

}

function updateNonLaborFinancial(btnObj) {
    var x;
    // console.log("id:" + btnObj.id);
    console.log("name:" + btnObj.name);
    // console.log("value:" + btnObj.value);
    var person = prompt("Enter new Value", btnObj.value);
    if (person !== null && person !== '') {
        if (!isNaN(person)) {
            var oldValue = document.getElementById(btnObj.id).value;
            //console.log("Old: "+oldValue);
            var newValue = person;
            //console.log("New: "+person);            
            request = getXmlHttpRequest2(btnObj.id);
            request.open("GET", "populateDropdown.php?type=updateNonLabor&value=" + person + "&string=" + btnObj.name, true);
            request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            request.send();

            var buttonIndex = btnObj.name.substr(btnObj.name.length - 1);
            var totalId = "";
            if (btnObj.name.indexOf("hours") > -1) {
                totalId = "totalHour" + buttonIndex;
            }
            else {
                totalId = "totalCost" + buttonIndex;
            }
            //console.log("Tot ("+totalId+"): "+document.getElementById(totalId).innerHTML);
            document.getElementById(totalId).innerHTML = parseInt(document.getElementById(totalId).innerHTML) + parseInt(newValue - oldValue);
        }
        else {
            //console.log("NaN");
            alert("Must be a number");
            //return null;
        }
    }

}

function getMaintenanceForm(id) {
    //hack to make the grid work
    if (id === "Edit Parameter" || id === "New Parameter" || id === "New EDR") {
        getParameterMaintenanceForm(id);
    }
    else if (id === "New Sensor" || id === "Edit Sensor") {
        getSensorMaintenanceForm(id);
    }
    else {
        getPlatformMaintenanceForm(id);
    }
}

function getRate() {
    $hours = document.getElementById('duration').value;
    $cost = document.getElementById('cost').value;
    if ($hours === "" || $cost === "") {
        document.getElementById("rateBox").innerHTML = "";
    }
    else {
        document.getElementById("rateBox").innerHTML = Math.round(document.getElementById('cost').value / document.getElementById('duration').value);
    }
}
function getEditParameterForm(id) {
    reqRequest = getXmlHttpRequest("editBox");
    reqRequest.open("POST", "populateDropdown.php?type=editParameterForm&id=" + id, true);
    reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    reqRequest.send();
}
function getParameterMaintenanceForm(id) {
    if (id === "Edit Parameter") {
        reqRequest = getXmlHttpRequest("editBox");
        reqRequest.open("POST", "populateDropdown.php?type=parameterMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("newBox").innerHTML = "";
    }
    if (id === "New Parameter" || id === "New EDR") {
        reqRequest = getXmlHttpRequest("newBox");
        reqRequest.open("POST", "populateDropdown.php?type=parameterMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("editBox").innerHTML = "";
    }
}
function getSensorMaintenanceForm(id) {
    if (id === "New Sensor") {
        reqRequest = getXmlHttpRequest("newBox");
        reqRequest.open("POST", "populateDropdown.php?type=sensorMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("editBox").innerHTML = "";
    }
    else if (id === "Edit Sensor") {
        reqRequest = getXmlHttpRequest("editBox");
        reqRequest.open("POST", "populateDropdown.php?type=sensorMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("newBox").innerHTML = "";
    }
}
/**
 * Fired when a user is selecting a platform maintenance option.
 * @param {type} id
 * @returns {undefined}
 */
function getPlatformMaintenanceForm(id) {
    if (id === "New Platform") {
        getNewSatelliteForm();
        document.getElementById("editBox").innerHTML = "";
    }
    else if (id === "Edit Platform") {
        reqRequest = getXmlHttpRequest("editBox");
        //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
        reqRequest.open("POST", "populateDropdown.php?type=platformMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("newBox").innerHTML = "";
    }
    else if (id === "New Platform Agency") {
        reqRequest = getXmlHttpRequest("satFormBox");
        //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
        reqRequest.open("POST", "populateDropdown.php?type=platformMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("editPlatformBox").innerHTML = "";
    }
    else if (id === "Edit Platform Agency") {
        reqRequest = getXmlHttpRequest("editPlatformBox");
        //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
        reqRequest.open("POST", "populateDropdown.php?type=platformMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("satFormBox").innerHTML = "";
    }
    else if (id === "New Platform Programme") {
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            reqRequest = new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            reqRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        reqRequest.onreadystatechange = function()
        {
            if (reqRequest.readyState === 4 && reqRequest.status === 200)
            {
                document.getElementById("satFormBox").innerHTML = reqRequest.responseText;
                $('#satLaunchDatepicker').datepicker({});
            }
        }
        //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
        reqRequest.open("POST", "populateDropdown.php?type=platformMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("editPlatformBox").innerHTML = "";
    }
    else if (id === "Edit Platform Programme") {
        reqRequest = getXmlHttpRequest("editPlatformBox");
        //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
        reqRequest.open("POST", "populateDropdown.php?type=platformMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("satFormBox").innerHTML = "";
    }
    else if (id === "New Platform Status") {
        reqRequest = getXmlHttpRequest("satFormBox");
        //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
        reqRequest.open("POST", "populateDropdown.php?type=platformMaintenance&id=" + id, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send();
        document.getElementById("editPlatformBox").innerHTML = "";
    }
}

/**
 * Requesting an AgencyEditForm for the given agency
 * @param {type} id the agency
 * @returns {undefined}
 */
function getEditAgencyForm(id) {
    reqRequest = getXmlHttpRequest("satFormBox");
    //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
    reqRequest.open("POST", "populateDropdown.php?type=editAgencyForm&id=" + id, true);
    reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    reqRequest.send();
    //document.getElementById("editPlatformBox").innerHTML = "";
}

function getEditSensorForm(id) {
    reqRequest = getXmlHttpRequest("editBox");
    //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
    reqRequest.open("POST", "populateDropdown.php?type=editSensorForm&id=" + id, true);
    reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    reqRequest.send();
    //document.getElementById("editPlatformBox").innerHTML = "";
}

/**
 * Requesting an editSatellite Form for the given satellite
 * @param {type} id the selected satellite
 * @returns {undefined}
 */
function getEditSatelliteForm(id) {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        reqRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        reqRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    reqRequest.onreadystatechange = function()
    {
        if (reqRequest.readyState === 4 && reqRequest.status === 200)
        {
            document.getElementById("newBox").innerHTML = reqRequest.responseText;
            $('#satLaunchDatepicker').datepicker({});
        }
    }
    //reqRequest = getXmlHttpRequest("satFormBox");
    //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
    reqRequest.open("POST", "populateDropdown.php?type=newSatForm&id=" + id, true);
    reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    reqRequest.send();
}

/**
 * Requesting an empty new satellite form
 * @returns {undefined}
 */
function getNewSatelliteForm() {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        reqRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        reqRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    reqRequest.onreadystatechange = function()
    {
        if (reqRequest.readyState === 4 && reqRequest.status === 200)
        {
            document.getElementById("newBox").innerHTML = reqRequest.responseText;
            $('#satLaunchDatepicker').datepicker({});
        }
    }
    //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
    reqRequest.open("POST", "populateDropdown.php?type=newSatForm", true);
    reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    reqRequest.send();
}

function getEditProgrammeForm(id) {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        reqRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        reqRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    reqRequest.onreadystatechange = function()
    {
        if (reqRequest.readyState === 4 && reqRequest.status === 200)
        {
            document.getElementById("satFormBox").innerHTML = reqRequest.responseText;
            $('#satLaunchDatepicker').datepicker({});
        }
    }
    //reqRequest = getXmlHttpRequest("satFormBox");
    //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
    reqRequest.open("POST", "populateDropdown.php?type=newProgrammeForm&id=" + id, true);
    reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    reqRequest.send();
}
/**
 * Requesting all of the requirements for the given fiscal year
 * @param {type} fiscalYear
 * @returns {undefined}
 */
function getReqTable(fiscalYear) {

    fyDropdown = document.getElementById("fyDropdown");
    if (validateDropdownSetisValid(fyDropdown)) {
        reqRequest = getXmlHttpRequest("reqBox");
        //document.getElementById("reqBox").innerHTML = "testing "+fiscalYear;
        reqRequest.open("POST", "populateDropdown.php?type=reqList&field=fyTable&id=" + fiscalYear, true);
        reqRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        reqRequest.send("id=" + fiscalYear + "");
    }
    else {
        document.getElementById("reqBox").innerHTML = "";
    }
}
//calls the php function to return a dropdown with parameters in it for the given reqID
//Used to fill fields when a user wants to edit an existing requirement
function getReqFields(str) {
    if (debug) {
        console.log(str);
    }
    if (str === "")
    {
        document.getElementById("edrBox").innerHTML = "";
        return;
    }
    if (str === "defaultSelection") {
        document.getElementById("edrBox").innerHTML = "Invalid Selection";
        document.getElementById("sourceBox").innerHTML = "";
        document.getElementById("priorityBox").innerHTML = "";
        document.getElementById("activeBox").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        paramRequest = new XMLHttpRequest();
        sourceRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        paramRequest = new ActiveXObject("Microsoft.XMLHTTP");
        sourceRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    paramRequest.onreadystatechange = function()
    {
        if (paramRequest.readyState === 4 && paramRequest.status === 200)
        {
            document.getElementById("edrBox").innerHTML = paramRequest.responseText;
        }
    };
    sourceRequest.onreadystatechange = function()
    {
        if (sourceRequest.readyState === 4 && sourceRequest.status === 200)
        {
            document.getElementById("sourceBox").innerHTML = sourceRequest.responseText;
        }
    };
    //the requirement name
    req = str;
    //returns a list of parameters associated with the given requirement
    paramRequest.open("POST", "populateDropdown.php?type=req&field=parameter&id=" + str, true);
    paramRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    paramRequest.send("id=" + str + "");
    //returns the source (document) for this requirement
    sourceRequest.open("POST", "populateDropdown.php?type=req&field=other&id=" + req, true);
    sourceRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    sourceRequest.send("id=" + str + "");
}

//select a fy and returns all req related to that fy (edit req)
function refreshReq(str) {

    //document.getElementById("reqBox").innerHTML = str;
    //return;
    if (str === "")
    {
        document.getElementById("edrBox").innerHTML = "";
        return;
    }
    if (str == "defaultSelection") {
        document.getElementById("edrBox").innerHTML = "";
        document.getElementById("reqBox").innerHTML = "";
        document.getElementById("sourceBox").innerHTML = "";
        document.getElementById("priorityBox").innerHTML = "";
        document.getElementById("activeBox").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        paramRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        paramRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    paramRequest.onreadystatechange = function()
    {
        if (paramRequest.readyState === 4 && paramRequest.status === 200)
        {
            //document.getElementById("reqBox").innerHTML ="test";
            document.getElementById("reqBox").innerHTML = paramRequest.responseText;
        }
    }
//xmlhttp.open("GET","getSatFromEdr.php?id="+str,true);
//xmlhttp.send();
    edr = str;
    paramRequest.open("POST", "populateDropdown.php?type=reqList&fy=" + str, true);
    paramRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    paramRequest.send("id=" + str + "");
    document.getElementById("edrBox").innerHTML = "";
    document.getElementById("priorityBox").innerHTML = "";
    document.getElementById("sourceBox").innerHTML = "";
    document.getElementById("activeBox").innerHTML = "";
}

//select a fy and returns all req related to that fy (edit req priorities)
function refreshReq2(str) {

    //document.getElementById("reqBox").innerHTML = str;
    //return;
    if (str === "")
    {
        document.getElementById("reqBox2").innerHTML = "";
        return;
    }
    if (str == "defaultSelection") {
        //document.getElementById("edrBox2").innerHTML = "Invalid Selection2";
        document.getElementById("reqBox2").innerHTML = "";
        document.getElementById("sourceBox").innerHTML = "";
        document.getElementById("priorityBox").innerHTML = "";
        document.getElementById("activeBox").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        paramRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        paramRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    paramRequest.onreadystatechange = function()
    {
        if (paramRequest.readyState === 4 && paramRequest.status === 200)
        {
            //document.getElementById("reqBox").innerHTML ="test";
            document.getElementById("reqBox2").innerHTML = paramRequest.responseText;
            //document.getElementById("reqBox2").innerHTML = "hello";
        }
    }
//xmlhttp.open("GET","getSatFromEdr.php?id="+str,true);
//xmlhttp.send();
    edr = str;
    paramRequest.open("POST", "populateDropdown.php?type=reqList&fy2=" + str, true);
    paramRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    paramRequest.send("id=" + str + "");
    document.getElementById("edrBox").innerHTML = "";
    document.getElementById("priorityBox").innerHTML = "";
    document.getElementById("sourceBox").innerHTML = "";
    document.getElementById("activeBox").innerHTML = "";
}

//calls the php function to fill the input fields (source, priority and active) with what is in the db for the given reqid and parameter
function getDbFieldsFromParameter(str) {

    if (str === "")
    {
        document.getElementById("edrBox").innerHTML = "";
        return;
    }
    if (str == "defaultSelection") {
        document.getElementById("edrBox").innerHTML = "Invalid Selection";
        //document.getElementById("satBox").innerHTML = "";
        //document.getElementById("sensorBox").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        sourceRequest = new XMLHttpRequest();
        priorityRequest = new XMLHttpRequest();
        activeRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        sourceRequest = new ActiveXObject("Microsoft.XMLHTTP");
        priorityRequest = new ActiveXObject("Microsoft.XMLHTTP");
        activeRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    sourceRequest.onreadystatechange = function()
    {
        if (sourceRequest.readyState === 4 && sourceRequest.status === 200)
        {
            document.getElementById("sourceBox").innerHTML = sourceRequest.responseText;
        }
    };
    priorityRequest.onreadystatechange = function()
    {
        if (priorityRequest.readyState === 4 && priorityRequest.status === 200)
        {
            document.getElementById("priorityBox").innerHTML = priorityRequest.responseText;
        }
    };
    activeRequest.onreadystatechange = function()
    {
        if (activeRequest.readyState === 4 && activeRequest.status === 200)
        {
            document.getElementById("activeBox").innerHTML = activeRequest.responseText;
        }
    };
    sourceRequest.open("POST", "populateDropdown.php?type=req&field=source&param=" + str + "&id=" + req, true);
    sourceRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    sourceRequest.send("id=" + str + "");
    priorityRequest.open("POST", "populateDropdown.php?type=req&field=priority&param=" + str + "&id=" + req, true);
    priorityRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    priorityRequest.send("id=" + str + "");
    activeRequest.open("POST", "populateDropdown.php?type=req&field=active&param=" + str + "&id=" + req, true);
    activeRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    activeRequest.send("id=" + str + "");
}

//called when user selects a requirement in the new subtask form
function getParametersFromReq(str) {
    if (debug) {
        console.log(str);
    }
    if (str === "")
    {
        document.getElementById("edrBox").innerHTML = "";
        return;
    }
    if (str == "defaultSelection") {
        document.getElementById("edrBox").innerHTML = "Invalid Selection";
        document.getElementById("satBox").innerHTML = "";
        document.getElementById("sensorBox").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        paramRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        paramRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    paramRequest.onreadystatechange = function()
    {
        if (paramRequest.readyState === 4 && paramRequest.status === 200)
        {
            document.getElementById("edrBox").innerHTML = paramRequest.responseText;
        }
    }
//xmlhttp.open("GET","getSatFromEdr.php?id="+str,true);
//xmlhttp.send();
    edr = str;
    paramRequest.open("POST", "populateDropdown.php?type=parameter&id=" + str, true);
    paramRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    paramRequest.send("id=" + str + "");
    document.getElementById("satBox").innerHTML = "";
    document.getElementById("sensorBox").innerHTML = "";
}

//an parameter has been selected now retrieve the satellites that apply
function getSatFromParameter(str)
{
    if (debug) {
        console.log(str);
    }
    if (str === "")
    {
        document.getElementById("satBox").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        paramRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        paramRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    paramRequest.onreadystatechange = function()
    {
        if (paramRequest.readyState === 4 && paramRequest.status === 200)
        {
            document.getElementById("satBox").innerHTML = paramRequest.responseText;
        }
    }
//xmlhttp.open("GET","getSatFromEdr.php?id="+str,true);
//xmlhttp.send();
    edr = str;
    paramRequest.open("POST", "populateDropdown.php?type=sat&id=" + str, true);
    paramRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    paramRequest.send("id=" + str + "");
    document.getElementById("sensorBox").innerHTML = "";
}

//an edr and sat has been selected now get the sensors that apply
function getSensorFromSatAndEdr(str)
{
    if (debug) {
        console.log(str);
    }
    if (str === "")
    {
        document.getElementById("testing").innerHTML = "";
        return;
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        paramRequest = new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        paramRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    paramRequest.onreadystatechange = function()
    {
        if (paramRequest.readyState === 4 && paramRequest.status === 200)
        {
            document.getElementById("sensorBox").innerHTML = paramRequest.responseText;
        }
    }
    paramRequest.open("POST", "populateDropdown.php?type=sensor&id=" + str, true);
    paramRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    if (edr.length === 0) {
        temp = document.getElementById("dropdownParameter");
        if (debug) {
            console.log("edr: " + temp.options[temp.selectedIndex].value);
        }
        edr = temp.options[temp.selectedIndex].value
    }
    paramRequest.send("edrID=" + edr + "");
}

//get the sensor that are on the selected satellite
function getSensorsFromSat(str)
{
    if (debug) {
        console.log(str);
    }
    if (str === "")
    {
        document.getElementById("testing").innerHTML = "";
        return;
    }
    paramRequest = getXmlHttpRequest("sensorsBox");
    paramRequest.open("GET", "populateDropdown.php?type=sensors&id=" + str, true);
    paramRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    paramRequest.send();
}

function getSensorsFromSat(str)
{
    paramRequest = getXmlHttpRequest("sensorsBox");
    paramRequest.open("GET", "populateDropdown.php?type=sensors&dropdown=single&id=" + str, true);
    paramRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    paramRequest.send();
}

function validateDropdownSetisValid(dropdown) {
    if (dropdown === undefined || dropdown.selectedIndex === 0) {
        return false;
    }
    return true;
}